use std::collections::HashMap;

use crate::router::api::i_router::IRouter;
use axum::Router;
use axum::extract::Path;
use axum::response::Html;
use axum::routing::get;

pub struct PathParams {}

impl IRouter for PathParams {
    fn init_router(&self, router: Router) -> Router {
        let gg = Router::new()
            .route("/:name", get(PathParams::path_one))
            .route("/:name/:age", get(PathParams::path_two))
            .route("/full/:fullpath", get(PathParams::path_three));
        router.nest("/path", gg)
    }
}

impl PathParams {
    pub fn new() -> PathParams {
        PathParams {}
    }
    pub async fn handler() -> Html<&'static str> {
        Html("<h1>Root</h1>")
    }
    // `Path` gives you the path parameters and deserializes them. See its docs for
    pub async fn path_one(Path(name): Path<String>) -> String {
        format!("path_handler Path<String>): {name}")
    }
    pub async fn path_two(Path((name, age)): Path<(String, i64)>) -> String {
        format!("path_handler Path<(String, i64)>): {name}, age: {age}")
    }
    pub async fn path_three(Path(fullpath): Path<HashMap<String, String>>) -> String {
        format!("path_handler Path<HashMap<String, String>>): {fullpath:?}")
    }
}
